﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace library_manage
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void B_DengLu_Click(object sender, EventArgs e)
        {
            //有账号
            //=获取数据
            string uname = this.TB_YHM_S.Text.Trim();
            string upass=this.TB_MM_S.Text.Trim();
            string gonghao = this.CB_YHLX_S.Text;
            //=判断工号是否有数据 
            string sql = "";
            if (gonghao=="超级用户")
            {
                //有 连接T_Administartor 表
                //====sql语句
                sql = string.Format("select * from T_Administrator where AdminiName='{0}' and AdminiPass='{1}'",uname,upass);
            }
            else
            {
                //无 连接T_Users 表
                sql = string.Format("select * from T_Users where userName='{0}' and PassWord='{1}'", uname, upass);
            }
            //===连接数据库
            var booktable = DBHelPer.Read(sql);
            //==判断是否登录正确
            if (booktable.Rows.Count > 0)
            {
                //=登录成功并跳转
                MessageBox.Show("登录成功！");
                Homepage zhuye = new Homepage();
                zhuye.Show();
            }
            else
            {
                MessageBox.Show("用户名或密码错误！");
            }
            

            //无账号
            //=去注册
        }
    }
}
